<script setup lang='ts'>
  import { onMounted, reactive } from 'vue';
  import { ChallengeApi } from '@/api/controller'
  import { getPlayEndTime, getDateArray, getTimestamp } from '@/utils'
  import { Toastloading } from '@/utils/public';
  import xmDatePicker from '@/components/xmDatePicker/index.vue';
  const action = reactive({
    list:[] as Array<any>,
    SessionList:[] as Array<any>,
    timeObj:getPlayEndTime(getDateArray('ymdhis'))
  })
  const listQuery = reactive({
    game_id:'',
  })
  const typeChange = ()=>{
    getList()
  }
  const getSession = async()=>{
    const loading = Toastloading()
    const res = await ChallengeApi.gameSwitch()
    const { data=[] } = res
    action.SessionList = data
    loading.close()
    getList()
  }
  const getList = async()=>{
    const loading = Toastloading()
    const { playTime, endTime } = action.timeObj
    const res = await ChallengeApi.statSearchAll({
      ...listQuery,
      date_st:getTimestamp(playTime,'s'),
      date_ed:getTimestamp(endTime,'s')
    })
    const { data={} } = res || {data:{}}
    action.list = [data]
    loading.close()
  }
  onMounted(() => {
    getSession()
  })
</script>

<template>
  <div class="xm-content">
    <div class="xm-headTab">
      <div class="labelBox">
        <div class="labelItem">
          <div class="label">游戏类型：</div>
          <el-select v-model="listQuery.game_id" @change="typeChange" clearable placeholder="请选择类型">
            <el-option
              v-for="item in action.SessionList"
              :label="item.game_name"
              :value="item.game_id"
            />
          </el-select>
        </div>
        <xmDatePicker v-model:timeval="action.timeObj" />
        <div class="labelItem">
          <el-button type="primary" @click="typeChange">查询</el-button>
        </div>
      </div>
    </div>
    <el-table
      class="xm-main xm-TableCenter"
      :data="action.list"
      border>
      <el-table-column min-width="120" prop="userNum" label="人数" />
      <el-table-column min-width="120" prop="payNum" label="消耗金豆"/>
      <el-table-column min-width="120" prop="getNum" label="参与产出钻石" />
      <el-table-column min-width="120" prop="offerNum" label="悬赏产出钻石" />
      <el-table-column min-width="120" prop="profitNum" label="利润金豆" />
      <el-table-column min-width="120" prop="profitNum" label="利润(元)">
        <template #default="scope">
          {{ scope.row.profitNum / 10 }}
        </template>
      </el-table-column>
      <el-table-column min-width="120" prop="profiRate" label="利润率">
        <template #default="scope">
          {{ scope.row.profiRate }}%
        </template>
      </el-table-column>
    </el-table>
  </div>
</template>

<style lang='scss' scoped>

</style>
